package com.bjmashibing.system.huawei.jdbc;

import com.bjmashibing.system.huawei.udp_cmd;
import com.bjmashibing.system.huawei.utils.JDBCUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Classname JdbcDruid
 * @Description TODO
 * @Date 2020/9/5/005 9:24
 * @Created by Administrator
 */
public class JdbcDruid {
    private final static Logger logger = LoggerFactory.getLogger(JdbcDruid.class);
    public void Insert(){
        /*
         * 完成添加操作：给account表添加一条记录
         */
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            //1.获取连接
            conn = JDBCUtils.getConnection();
            //2.定义sql
            String sql = "insert into account values(null,?,?)";
            //3.获取pstmt对象
            pstmt = conn.prepareStatement(sql);
            //4.给？赋值
            pstmt.setString(1,"王五11");
            pstmt.setDouble(2,666666);
            //5.执行sql
            int count = pstmt.executeUpdate();
            logger.info("count=" + count);
        } catch (SQLException e) {
            logger.info("Insert,error=" ,e);
            e.printStackTrace();
        }finally {
            //6. 释放资源
            JDBCUtils.close(pstmt,conn);
        }
    }
}
